<?php

namespace app\api\controller;
use app\common\controller\Frontend;
use app\admin\model\ServerIpInventory as AdminServerIpInventory;
use app\admin\model\binance\KeySecret as BinanceKeySecret;

class ServerIpInventory extends Frontend
{
    /**
     * 无需登录的方法
     * 访问本控制器的此方法，无需会员登录
     */
    protected array $noNeedLogin = ["getIPuserInfo"];

    /**
     * 无需鉴权的方法
     */
    protected array $noNeedPermission = [];


    public function initialize(): void
    {
        parent::initialize();
        $this->model = new AdminServerIpInventory();
        $this->baLogs = new BinanceKeySecret();
    }

    /**
     * 通过IP返回对应的用户信息
     */
    public  function getIPuserInfo():void
    {
        $ip = $this->request->ip();
        $res = $this->model->where("ip", $ip)->find();
        if(empty($res)) {
            $this->error("未匹配到相同的服务器IP：".$ip);
            die();
        }
        $keys_logs = $res->ba_keys_ids;
        $baLogs = $this->baLogs->where("id", "in", $keys_logs)->select();

        $res = array(
            "status" => $res->status,
            "accounts" => $baLogs->toArray()
        );
        $this->success("获取成功", $res);
        die();
    }
}